home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 011 / macro.arc / MACRO.DOC next >
Encoding:
Text File  |  1985-07-01  |  3.3 KB  |  131 lines

  1.  
  2. Page 1                                                             macro
  3.  
  4.  
  5.  
  6. PROGRAM
  7.     macro -- expand string definitions, with arguments
  8.  
  9. USAGE
  10.     macro
  11.  
  12. FUNCTION
  13.     macro reads its input, looking for macro definitions of the form
  14.  
  15.             define(ident,string)
  16.  
  17.     and   writes  its  output  with  each  subsequent  instance  of  the
  18.     identifier ident replaced by the arbitrary sequence  of  characters
  19.     string.
  20.  
  21.     Within  a  replacement string, any dollar sign $ followed by a digit
  22.     is replaced by an argument corresponding to  that  digit.  Arguments
  23.     are written as a parenthesized list of strings following an instance
  24.     of the identifier, e.g.,
  25.  
  26.         ident(arg1,arg2,...)
  27.  
  28.     So $1 is replaced in the replacement string by arg1, $2 by arg2, and
  29.     so  on; $0 is replaced by ident. Missing arguments are taken as null
  30.     strings; extra arguments are ignored.
  31.  
  32.     The replacement string  in  a  definition  is  expanded  before  the
  33.     definition  occurs, except that any sequence of characters between a
  34.     grave ` and a balancing apostrophe ' is taken  literally,  with  the
  35.     grave  and apostrophe removed. Thus, it is possible to make an alias
  36.     for define by writing
  37.  
  38.             define(def,`define($1,$2)')
  39.  
  40.  
  41.     Additional predefined built-ins are:
  42.  
  43.     ifelse(a,b,c,d) is replaced by the string c if the string a  exactly
  44.     matches the string b; otherwise it is replaced by the string d.
  45.  
  46.     expr(expression) is replaced by the decimal string representation of
  47.     the   numeric  value  of  expression.  For  correct  operation,  the
  48.     expression must consist of parentheses, integer operands written  as
  49.     decimal  digit  strings,  and  the  operators  +,  -,  *, / (integer
  50.     division), and  %  (remainder).  Multiplication  and  division  bind
  51.     tighter  than  addition and subtraction, but parentheses may be used
  52.     to alter this order.
  53.  
  54.     substr(s,m,n) is replaced by the substring of s starting at location
  55.     m (counting from one) and continuing at most n characters. If  n  is
  56.     omitted,  it  is  taken  as a very large number; if m is outside the
  57.     string, the replacement string is null. m and n may  be  expressions
  58.     suitable for expr.
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67. Page 2                                                             macro
  68.  
  69.  
  70.     len(s)  is  replaced  by  the  string representing the length of its
  71.     argument in characters.
  72.  
  73.     changeq(xy) changes the quote characters  to  x  and  y.  changeq()
  74.     changes them back to ` and '.
  75.  
  76.     Each   replacement   string   is   rescanned  for  further  possible
  77.     replacements, permitting multi-level definitions to be  expanded  to
  78.     final form.
  79.  
  80. EXAMPLE
  81.     The macro len could be written in terms of the other built-ins as:
  82.  
  83.         define(`len',`ifelse($1,,0,`expr(1+len(substr($1,2)))')')
  84.  
  85.  
  86. BUGS
  87.     A  recursive  definition  of  the  form  define(x,x)  will  cause an
  88.     infinite loop.
  89.     Expression evaluation is fragile. There is no unary minus.
  90.     It is unwise to use parentheses as quote characters.
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.